package com.porm.framework.handler;

import com.porm.framework.mapper.Mapper;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * CoreHandler
 *
 * @author humdeef
 * @date 2018/11/12
 */
public class CoreHandler implements InvocationHandler {
    private Mapper mapper;

    public CoreHandler(Mapper mapper) {
        this.mapper = mapper;
    }

    public void setMapper(Mapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getName().equals("save")) {
            System.out.println("保存操作..");
        } else if (method.getName().equals("update")) {
            System.out.println("更新操作");
        } else if (method.getName().equals("delete")) {
            System.out.println("删除操作");
        }
        Object invoke = method.invoke(mapper, args);
        System.out.println(invoke);
        return 1;
    }
}
